<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%String path=request.getContextPath(); %>
<!DOCTYPE html>
<html>
<%
String username = "";
Cookie cookies[] = request.getCookies();
if(cookies!=null)
{
	for(Cookie cookie:cookies)
	{
		if(cookie.getName().equals("username"))
		{
			username = cookie.getValue();
		}
	}
}
%>
	<head>
		<meta charset="utf-8" />
		<title>登录</title>
		<link rel="stylesheet" href="<%=path %>/static/css/login.css" />
	</head>

	<body>
		<div class="body">
			<p class="logo"><img width="200" src="<%=path %>/static/image/nangua.jpg"></p>
			<div class="body_count">
				<div class="login_count">
					<div class="login_count_a">

						<div id="all" style="margin-top: 0;margin-bottom: 10">
							<ul  id="option" style="border: 0">
								<li style="margin-left:50" class="active login_left">用户登录</li>
								<br>
								
								<span style="color:red" class="span" id="span">
								<%
									String msg = request.getParameter("msg");
									if("error".equals(msg))
									{%>
										用户名或者密码错误，请重新登陆
								<%
									}
									
								%>
								</span>
							</ul>
							<form id="myform" action="<%=request.getContextPath()%>/UserInfoServlet?action=login" method="post">
							<ul id="card">
							
								<li class="active">
									<!--输入框-->
									<div class="login_bot_count">
										<img src="<%=path %>/static/image/tubiao-07.png" alt="" />
										<input type="text" name="username" value="<%=username %>" id="name" placeholder="请输入账号" />
									</div>
                                    <div class="login_bot_count">
										<img src="<%=path %>/static/image/tubiao-06.png" alt="" />
										<input type="password" name="password" id="password" placeholder="请输入密码"  />
									</div>
									<div class="login_bot_count">
										<img style="width:100;height:30" id="codeImg" src="<%=request.getContextPath()%>/CodeServlet?action=code"/>
										<input type="text" name="code" id="code" placeholder="请输入验证码"  />
									</div>

									<div class="login_bot">
										

										<p><input type="checkbox" name="remenber" value="1" />记住用户</p><a style="color:gray" href="<%=path%>/registe.jsp">没注册？去注册</a>
									</div>
									<!--登录按钮-->
									<input type="button" id="sub" value="登录" class="login_button">
								</li>
								
							</ul>
							</form>
						</div>

					</div>
				</div>

			</div>
		</div>

		<script src="https://www.jq22.com/jquery/jquery-1.10.2.js"></script>
		<script type="text/javascript" src="js/login.js" ></script>
	</body>

</html>

<script>
$(function(){
	$("#sub").click(function(){
		$("#span").html("");
		var code=$("#code").val();
		$.ajax({
			url:"<%=request.getContextPath()%>/CodeServlet?action=checkCode",
			data:{code:code},
			success:function(data){
				if("ok"==data){
					$("#myform").submit();
					$("#span").html("");
				}
				else{
					$("#span").html("验证码错误，请重新输入！");
					$("#code").select();
				}
			}
		})
	})
	
	//点击切换验证码
	$("#codeImg").click(function(){
		$(this).attr("src","<%=request.getContextPath()%>/CodeServlet?action=code&rand="+Math.random());
	});	
});
</script>